import KY3D from "@/editor/KY3D";
import { APIEvent } from "@/libs/const/event";
import { ClampToEdgeWrapping, RepeatWrapping, Texture, TextureLoader } from "three";
import { LocalStorage } from "../editor/framework/net/cache/LocalStorage";
import SchemeModule from "./data/scheme/SchemeModule";
import SettingModule from "./data/setting/SettingModule";

export default class API implements IStartUp {

    /** 设置 */
    setting: SettingModule;

    /** 登录验证 ... 等等一堆请求*/

    /** 方案 */
    scheme: SchemeModule;

    static pic: Texture;


    constructor() {
        /* 浏览器缓存*/
        LocalStorage.__init__();
    }

    async startUp() {
        console.log("login start")

        await this.loadTestPicture();
        // 等待请求
        await this.moduleInit();

        console.log("login end");

        // 请求数据完毕，可能需要检查下

        // 进入程序
        setTimeout(() => {
            KY3D.ED.event(APIEvent.API_LOAD_COMPLETE);
        }, 1000);

    }

    async loadTestPicture() {
        let right = './image/tiled_oak.jpg';
        let texture = new TextureLoader();
        let rightTexture = texture.load(right);
        rightTexture.wrapS = ClampToEdgeWrapping;
        rightTexture.wrapT = ClampToEdgeWrapping;
        // rightTexture.repeat.set(4, 4);
        API.pic = rightTexture;

    }

    async moduleInit() {

        this.setting = new SettingModule();
        await this.setting.load();

        // 登录验证，权限验证...

        // ....

        //  一堆请求验证...

        this.scheme = new SchemeModule();
        await this.scheme.load();

    }

}